package ssm.another;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Created by libing on 2017/2/8.
 */
@Controller
@RequestMapping("upload")
public class FileUploadController {

    @RequestMapping("uploadPic")
    @ResponseBody
    public UploadResult uploadPicture(HttpSession session, HttpServletRequest request, @RequestParam("multiInput") MultipartFile temp_file)throws Exception{
        UploadResult result = new UploadResult();
        String name = FileUtils.createFile(temp_file,request);
        if (name == null || "".equals(name)){
            result.setStatus("U001");
            result.setMsg("图片上传失败");
        }else {
            result.setStatus("U002");
            result.setMsg("图片上传成功");
        }
        return result;
    }

}
